<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }


        .box {
            width: 100%;
            height: 50px;
            display: flex;
            justify-content: space-around;
            align-items: center;
            font-size: 20px;
            font-weight: bold;
            cursor: pointer;
            position: fixed;
            bottom: 0;

        }

        h1 {
            width: 100%;
            height: 200px;
            text-align: center;
        }

        .active {
            border-bottom: 5px solid rgb(21, 141, 227);
        }

        .navbar {
            width: 100%;
            background-color: red;
            color: #fff;
            height: 40px;
            line-height: 40px;
            text-align: center;
            display: flex;
        }

        .navbar div {
            flex: 1;
        }

        .left {
            text-align: left;
        }

        .center {
            text-align: center;
        }

        .right {
            text-align: right;
        }
    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<!-- 用来将jsx语法转化为js语法 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<script type="text/babel">

    class App extends React.Component {
        state = {
            boxlist: ['首页', '分类', '购物车', '我的'],
            activeindex: 0
        }
        render() {
            return (
                <div>
                    <div className='box'>
                        {
                            this.state.boxlist.map((item, index) => {
                                return (
                                    <div key={index} className={this.state.activeindex === index ? 'active' : ''}>
                                        onClick={() => {
                                            this.setState({
                                                activeindex: index
                                            })
                                        }}{item} </div>

                                )
                            })
                        }
                    </div>

                    {this.state.activeindex === 0 && <Home />}
                    {this.state.activeindex === 1 && <Sort />}
                    {this.state.activeindex === 2 && <Cart />}
                    {this.state.activeindex === 3 && <Mine />}
                </div>
            )
        }
    }
    class Home extends React.Component {
        render() {
            return (
                <NavBar>
                    <div>home</div>
                    <div>首页</div>
                    <div>三</div>
                </NavBar>
            )
        }
    }
    class Sort extends React.Component {
        render() {
            return (
                <NavBar>
                    <div>《</div>
                    <div>分类</div>
                    <div>x</div>
                </NavBar>
            )
        }
    }
    class Cart extends React.Component {
        render() {
            return (
                <NavBar>
                    <div>
                        购物车图标
                    </div>
                    <div>
                        购物车</div>
                    <div></div>
                </NavBar>
            )
        }
    }
    class Mine extends React.Component {
        render() {
            return (
                <NavBar>
                    <div>＜</div>
                    <div>我的</div>
                    <div>X</div>
                </NavBar>
            )
        }
    }
    class NavBar extends React.Component {
        render() {
            return (
                <div>
                    <div className='navbar'>
                        <div className='left'>
                            {this.props.children[0]}
                        </div>
                        <div className='center'>
                            {this.props.children[1]}
                        </div>
                        <div className='right'>
                            {this.props.children[2]}
                        </div>

                    </div>
                </div>
            )
        }
    }
    ReactDOM.render(<App />, document.getElementById('root'))
</script>

</html>